package org.achartengine.internal;

import android.graphics.RectF;
import android.view.MotionEvent;
import org.achartengine.internal.chart.k;
import org.achartengine.internal.renderer.XYMultipleSeriesRenderer;

/* loaded from: classes2.dex */
public class d implements ITouchHandler {
    private XYMultipleSeriesRenderer a;
    private float b;
    private float c;
    private float d;
    private float e;
    private RectF f;
    private org.achartengine.internal.a.c g;
    private org.achartengine.internal.a.d h;
    private GraphicalView i;

    public d(GraphicalView graphicalView, org.achartengine.internal.chart.a aVar) {
        this.f = new RectF();
        this.i = graphicalView;
        this.f = graphicalView.e();
        k kVar = (k) aVar;
        XYMultipleSeriesRenderer e = kVar.e();
        this.a = e;
        if (e.S() || this.a.T()) {
            this.g = new org.achartengine.internal.a.c(kVar);
        }
        if (this.a.U() || this.a.V()) {
            this.h = new org.achartengine.internal.a.d(kVar, true, 1.0f);
        }
    }

    @Override // org.achartengine.internal.ITouchHandler
    public void handleTouch(MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        if (this.a == null || action != 2) {
            if (action != 0) {
                if (action == 1 || action == 6) {
                    this.b = 0.0f;
                    this.c = 0.0f;
                    this.d = 0.0f;
                    this.e = 0.0f;
                    if (action == 6) {
                        this.b = -1.0f;
                        this.c = -1.0f;
                        return;
                    }
                    return;
                }
                return;
            }
            this.b = motionEvent.getX(0);
            this.c = motionEvent.getY(0);
            XYMultipleSeriesRenderer xYMultipleSeriesRenderer = this.a;
            if (xYMultipleSeriesRenderer != null) {
                if ((xYMultipleSeriesRenderer.U() || this.a.V()) && this.f.contains(this.b, this.c)) {
                    if (this.b < this.f.left + (this.f.width() / 3.0f)) {
                        this.i.b();
                    } else if (this.b < this.f.left + ((this.f.width() * 2.0f) / 3.0f)) {
                        this.i.c();
                    } else {
                        this.i.d();
                    }
                }
            }
        } else if (this.b >= 0.0f || this.c >= 0.0f) {
            float x = motionEvent.getX(0);
            float y = motionEvent.getY(0);
            if (motionEvent.getPointerCount() > 1 && ((this.d >= 0.0f || this.e >= 0.0f) && (this.a.U() || this.a.V()))) {
                float x2 = motionEvent.getX(1);
                float y2 = motionEvent.getY(1);
                float abs = Math.abs(x - this.b) >= Math.abs(y - this.c) ? Math.abs(x - x2) / Math.abs(this.b - this.d) : Math.abs(y - y2) / Math.abs(this.c - this.e);
                double d = abs;
                if (d > 0.909d && d < 1.1d) {
                    this.h.a(abs);
                    this.h.b();
                }
                this.d = x2;
                this.e = y2;
            } else if (this.a.S() || this.a.T()) {
                this.g.a(this.b, this.c, x, y);
                this.d = 0.0f;
                this.e = 0.0f;
            }
            this.b = x;
            this.c = y;
            this.i.f();
        }
    }
}
